<template>
	<view class="main">
		<view class="time" @click="go">
			{{ time == 0 ? '' : time }}
			<text>跳过</text>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			time: 3
			
		};
	},
	onLoad() {
		this.dateTime();
	},

	methods: {
		go() {
			this.time = 0;
		},
		dateTime() {
			let timer = setInterval(() => {
				if (this.time > 0) {
					this.time--;
				} else {
					clearInterval(timer);

					try {
						const value = uni.getStorageSync('token') || '';
						console.log('当前token----------', value);
						if (value) {
							uni.switchTab({
								url: '/pages/Chartered/index'
							});
						} else {
							uni.redirectTo({
								url: '/pages/Login/index'
							});
						}
					} catch {
						// error
						uni.redirectTo({
							url: '/pages/Login/index'
						});
					}

					// uni.getStorageSync({
					// 	key: 'token',
					// 	success: function(res) {
					// 	console.log('userInfo---------', res)
					// 		if (!res.data.token) {
					// 			uni.redirectTo({
					// 				url: '/pages/Login/index'
					// 			});

					// 		} else {
					// 			uni.switchTab({
					// 			    url: '/pages/index/index'
					// 			});
					// 		}
					// 	},
					// 	fail: function(err) {
					// 		//console.log('userInfo---------', err)
					// 		uni.redirectTo({
					// 			url: '/pages/Login/index'
					// 		});
					// 	}
					// });
				}
			}, 1000);
		}
	}
};
</script>

<style lang="scss" scoped>
.main {
	width: 100vw;
	height: 100vh;
	background: url() center/cover no-repeat;

	.time {
		width: 130rpx;
		height: 60rpx;
		color: #ffffff;
		border-radius: 20rpx;
		background-color: rgba(255, 255, 255, 0.2);
		text-align: center;
		line-height: 60rpx;
		font-size: 14px;
		position: fixed;
		right: 20rpx;
		top: 80rpx;
		text {
			margin-left: 10rpx;
		}
	}
}
</style>
